package com.example.demo.util;

import com.example.demo.model.dto.PrizeDTO;
import com.example.demo.model.entity.Prize;

import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

public class PrizeConverter {

    public static Prize convert(PrizeDTO prizeDTO) {
        Prize prize = new Prize();
        prize.setLevel(prizeDTO.getLevel());
        prize.setNumber(prizeDTO.getNumber());
        prize.setType(prizeDTO.getType());
        prize.setProbability(prizeDTO.getProbability());
        if (prize.getType() == 0) {
            prize.setGoodsId(prizeDTO.getPrizeId());
        } else if (prize.getType() == 1) {
            prize.setCouponId(prizeDTO.getPrizeId());
        }
        return prize;
    }

    public static List<Prize> convert(List<PrizeDTO> prizeDTOList) {
        List<Prize> prizeList = new ArrayList<>();
        for(PrizeDTO prizeDTO : prizeDTOList) {
            Prize prize = convert(prizeDTO);
            prizeList.add(prize);
        }
        return prizeList;
    }
}
